﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';

version = '1.0.0'; //版本号 version
charset = 'UTF-8'; //字符编码Character Set
signMethod = 'MD5'; //签名方法Signing Method
transType = '01';  //交易类型 Transaction type
merId = '880000000000564'; //商户代码 Merchant ID
security_key = 'JWvxC1zlOiFLWXgGBqrAndMf5CL6XPoT';
</cfscript>

<!---银联移动支付--->
<!---获取TN--->
<cffunction name="tn" access="remote" returntype="any" returnFormat="json">
<cfparam name="transType" default="01">
<cfscript>
j = {"success":"0"};
//backEndUrl = 'http://simp.chinalaohu.com/UPMP/'; //通知URL Notify URL 商户后台URL
orderTime = datetimeformat(now(),'yyyymmddHHNNSS'); //交易开始日期时间 Start Date & Time For Transaction
if (not isdefined('orderNumber')){
orderNumber = datetimeformat(now(),'yyyymmddHHNNSS'); //商户订单号 Merchant Order Number
}
if (not isdefined('orderAmount')){
orderAmount = '2'; //交易金额 Purchase Amount
}
//orderCurrency = '156';  //交易币种 Purchase Currency
//sign1 = 'backEndUrl=' & backEndUrl & '&charset=' & charset & '&merId=' & merId & '&orderAmount=' & orderAmount & '&orderCurrency=' & orderCurrency & '&orderNumber=' & orderNumber & '&orderTime=' & orderTime & '&transType=' & transType & '&version=' & version;
//sign2 = sign1 & '&' & lcase(hash(security_key,'md5'));
//signature = lcase(hash(sign2,'md5'));


//transType = '01'; //交易
//transType = '31'; //撤销

</cfscript>

<cfhttp url="http://adio.chinalaohu.com/php/UPMP/examples/tn.php" method="post" result="rs">
  <cfhttpparam type="formfield" name="orderTime" value="#orderTime#">
  <cfhttpparam type="formfield" name="orderNumber" value="#orderNumber#">
  <cfhttpparam type="formfield" name="orderAmount" value="#orderAmount#">
  <cfhttpparam type="formfield" name="transType" value="#transType#">
</cfhttp>
<cfscript>
tnjson = rs.Filecontent;
if (isjson(tnjson)){
	j = {"success":"1","UPMP":DeserializeJSON(tnjson)};
}

</cfscript>


<cfscript>
j = createObject("component",'cfjson').encode(j);
return j;
</cfscript>


<!---  <cfhttpparam type="formfield" name="backEndUrl" value="#backEndUrl#">
  <cfhttpparam type="formfield" name="charset" value="#charset#">
  <cfhttpparam type="formfield" name="merId" value="#merId#">
  <cfhttpparam type="formfield" name="orderAmount" value="#orderAmount#">
  <cfhttpparam type="formfield" name="orderCurrency" value="#orderCurrency#">
  <cfhttpparam type="formfield" name="orderNumber" value="#orderNumber#">
  <cfhttpparam type="formfield" name="orderTime" value="#orderTime#">
  <cfhttpparam type="formfield" name="transType" value="#transType#">
  <cfhttpparam type="formfield" name="version" value="#version#">
  <cfhttpparam type="formfield" name="signature" value="#signature#">
  
  <cfhttpparam type="formfield" name="signMethod" value="#signMethod#">
--->
<!---<cfhttp url="http://222.66.233.198:8080/gateway/merchant/trade" method="POST" result="result" charset="utf-8" port="8080">

  <cfhttpparam type="formfield" name="version" value="#version#">
  <cfhttpparam type="formfield" name="charset" value="#charset#">
  <cfhttpparam type="formfield" name="signMethod" value="#signMethod#">
  <cfhttpparam type="formfield" name="signature" value="#signature#">
  <cfhttpparam type="formfield" name="transType" value="#transType#">
  <cfhttpparam type="formfield" name="merId" value="#merId#">
  <cfhttpparam type="formfield" name="backEndUrl" value="#backEndUrl#">
  <cfhttpparam type="formfield" name="orderTime" value="#orderTime#">
  <cfhttpparam type="formfield" name="orderNumber" value="#orderNumber#">
  <cfhttpparam type="formfield" name="orderAmount" value="#orderAmount#">
  <cfhttpparam type="formfield" name="orderCurrency" value="#orderCurrency#">
  
</cfhttp> 
<cfdump var="#result#">
--->
</cffunction>
  

<!---异步返回信息---> 
<cffunction access="remote" name="back" returntype="any">

<cfparam name="respMsg" default="">
<cfparam name="SYSRESERVED" default="">

<cfquery datasource="#DB#">
insert into upmptmp(dt)
value(#now()#)
</cfquery>

<cfquery datasource="#DB#">
insert into UPMP_back(dt,version,charset,signMethod,signature,transType,merId,transStatus,respMsg,qn,orderTime,orderNumber,settleAmount,settleCurrency,SYSRESERVED)
value(#now()#,'#version#','#charset#','#signMethod#','#signature#','#transType#',
'#merId#','#transStatus#','#respMsg#','#qn#','#orderTime#','#orderNumber#','#settleAmount#','#settleCurrency#','#SYSRESERVED#')
</cfquery>
</cffunction>

</cfcomponent>